package cn.dujc.superkid.adapter;

import android.content.Context;
import android.content.Intent;
import android.support.annotation.Nullable;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import java.util.List;

import cn.dujc.core.adapter.BaseAdapter;
import cn.dujc.core.adapter.BaseViewHolder;
import cn.dujc.superkid.R;
import cn.dujc.superkid.activities.CourseVideoActivity;
import cn.dujc.superkid.activities.CupVideoActivity;
import cn.dujc.superkid.bean.LearningProcessResult;
import cn.dujc.superkid.bean.RecordBean;

public class MeRecordAdapter extends RecyclerView.Adapter<MeRecordAdapter.ViewHolder> {
    private Context context;

    public MeRecordAdapter(Context context) {
        this.context = context;
    }

    public void setDatas(List<RecordBean> datas) {
        this.datas = datas;
        notifyDataSetChanged();
    }

    private List<RecordBean> datas;

    @Override
    public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(context).inflate(R.layout.item_merecord, null);
        return new ViewHolder(view);
    }

    @Override
    public void onBindViewHolder(ViewHolder holder, final int position) {
        holder.title.setText(datas.get(position).getTitle());
        holder.content.setText(datas.get(position).getContent());
        holder.item.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent in = new Intent();
                if (datas.get(position).getType() == 3) {
                    in.setClass(context, CupVideoActivity.class);
                }else{
                    in.setClass(context, CourseVideoActivity.class);
                }
                in.putExtra("video_id", datas.get(position).getVideo_id());
                in.putExtra("course_id", datas.get(position).getCourse_id());
                in.putExtra("is_learn", "2");
                in.putExtra("videoTitle",datas.get(position).getContent());
                context.startActivity(in);
            }
        });
    }

    @Override
    public int getItemCount() {
        return datas == null ? 0 : datas.size();
    }

    static class ViewHolder extends RecyclerView.ViewHolder {
        TextView title;
        TextView content;
        View item;
        public ViewHolder(View itemView) {
            super(itemView);
            item=itemView;
            title=itemView.findViewById(R.id.tv_knowledge_name);
            content=itemView.findViewById(R.id.tv_title);
        }
    }
}
